import Cookies from 'js-cookie'
let util = {
    judeEnv: () => {
        // 判断userAgent中是否拥有标识
        function matchUserAgent(reg) {
            return !!navigator.userAgent.match(reg)
        }
        // 是否从蜂巢进入
        function isFengChao() {
            let bool = false
            matchUserAgent(/CombWebView/) ? bool = true : bool = false
            return bool
        }
        // 是否从信息门户进入
        function isXXMH() {
            let bool = false
            function GetRequest() {
                var url = location.search // 获取url中'?'符后的字串
                // eslint-disable-next-line
                var theRequest = new Object()
                if (url.indexOf('?') !== -1) {
                    var str = url.substr(1)
                    var strs = str.split('&')
                    for (var i = 0; i < strs.length; i++) {
                        theRequest[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
                    }
                }
                return theRequest
            }
            let query = GetRequest()
            if (query.combStr) {
                bool = true
                Cookies.set('combStr', query.combStr)
            }
            // Cookies.set('combStr', window.config.RSA.code)
            return bool
        }
        let environment = {
            isMobie: false,
            isFengChao: false,
            isXXMH: false
        }
        isFengChao() ? environment.isFengChao = true : environment.isFengChao = false
        isXXMH() ? environment.isXXMH = true : environment.isXXMH = false
        return environment
    }
}

export default util
